<%-content_for :page_title do-%>
  新建课程
<%-end-%>
<script type="text/javascript">
  $().ready(function() {
    $("#course_form").validate({
      rules: { "course[title]": {
          required: true,
          maxlength: 16
        },"course[description]": {
          required: true,
          maxlength: 300
        },"course[tag_list]": {
          required: true,
          maxlength :20
        }
      },
      messages:{
        "course[title]": {
          required: "请输入课程标题",
          maxlength: "最多只能输入16个字符"
        },"course[description]": {
          required: "请输入课程描述",
          maxlength: "最多只能输入300个字符"
        },"course[tag_list]": {
          required: "请输入课程标签",
          maxlength: "最多只能输入20个字符"
        }
      },
      errorPlacement: function(error,element){
        error.appendTo(element.next());
      }
    })
  });
</script>
<div id="new_course_pannel">
  <div class="sub_pannel">
    <div class="content">
      <div class="title">
        <span class="text">
          创建新课程 步骤二
        </span>
      </div>
      <% form_for(@course,:html => {:id => 'course_form'}) do |f| %>
        <p>
          <%=label_tag "课程分类", nil ,:class=>'label'%>
          <span style="display:block;margin:10px 0px;font-size:1.1em;"><%= @category.name %></span>
        </p>
        <p>
          <%=label_tag "课程标题", nil ,:class=>'label'%>
          <%= f.text_field :title, :class => "text" %><span></span><span class="hint_message">不能为空，最多16个字符</span>
        </p>
        <p>
          <%=label_tag "课程描述", nil ,:class=>'label'%>
          <%=f.text_area :description, :class => 'text'%><span></span>
          <span class="hint_message">不能为空，最多300个字符</span>
        </p>
        <p>
          <%=label_tag "标签", nil ,:class=>'label'%>
          <%= f.text_field :tag_list, :class => "text",:onblur => "change_tag_token(this)"%><span></span>
          <span class="hint_message">标签之间用英文状态下的“,”分开</span>
        </p>
        <p>
          <%=label_tag "课程权限", nil ,:class=>'label'%>
          <%= select_tag("course[is_public]",options_for_select({"不公开" => "0", "公开" => "1"},"1"))%>
          <span class="hint_message">如果选择公开，所有用户都可以使用您创建的课程，如果选择不公开，只有您或者您的企业用户可以使用</span>
        </p>
        <p class="p_submit">
          <%= hidden_field(:course, "category_id", :value => @category.id )%>
          <%= f.submit '创建课程', :class=>'submit'%>
        </p>
      <%end%>
    </div>
  </div>
</div>
<script type="text/javascript" language="javascript">
  function change_tag_token(tag_field){
    var tag_content = tag_field.value;
    tag_content = tag_content.replace(/\s/g,",");
    tag_content = tag_content.replace(/，/g,",");
    tag_field.value = tag_content;
  }
</script>